<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>javascript 阶段</title>
    <style>
        body {
            font-size: 30px;
        }
        p , h3 {
            padding: 0;
            margin: 0;
        }
    </style>
</head>
<body>
    <h3>页面(1)</h3>
    <p>2021-08-24</p>
    <p>今天的天气很好!</p>

    <script>
        // 字符串
        var weather = "今天的天气很好!";
        var time = "2021-08-24";
        // 设置cookie
        // document.cookie = "name = value"
        // document.cookie = "weather=" + weather 
        // document.cookie = "time=" + time

        // 例如:   缓存数据的有效时间
      
        // 获取当前的时间戳
        var curTime = new Date().getTime();
        console.log(curTime);
        // 2小时后的时间戳
        var ms = 2 * 60 * 60 * 1000;
        // 未来的时间戳
        var futureTime = curTime + ms;
        // 设置日期
        var dt = new Date();
        dt.setTime(futureTime);
        console.log(dt);

        // 缓存数据的有效时间
        document.cookie = "weather=" + weather +"; expires="+dt
        document.cookie = "time=" + time +"; expires="+dt
        document.cookie = "color=" + "red" +"; expires="+dt



        // var world = "我是真的很喜欢你";
        // var drink = "可乐";
        // document.cookie = "world" + world ;
        // document.cookie = "drink" + drink ;

    </script>
</body>
</html>